package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.douluodalu.CrossDouLuoDaLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_DOU_LUO_DA_LU_TEAM_CREATE, desc = "创建队伍")
public class CrossDouLuoDaLuCreateTeamCmd extends CrossUnionCommand {

    int activityId;
    boolean hasEnoughItems;
    long playerId;
    String name;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        DouLuoDaLuProto.DouLuoDaLuCreateTeamCrossReqMsg reqMsg = DouLuoDaLuProto.DouLuoDaLuCreateTeamCrossReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        hasEnoughItems = reqMsg.getHasEnoughItems();
        playerId = packet.getPlayerId();
        name = reqMsg.getTeamName();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(GameProtocol.S_DOU_LUO_DA_LU_TEAM_CREATE_FROM_CROSS,
                CrossDouLuoDaLuMgr.createTeam(activityId, playerId, name, hasEnoughItems)));

    }

    @Override
    public void sendData() {

    }
}
